package com.zcb.qingshoudan.activity;

import android.app.Activity;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.zcb.qingshoudan.R;
import com.zcb.qingshoudan.adapter.GatherHistoryAdapter;
import com.zcb.qingshoudan.adapter.VerificationHistoryAdapter;
import com.zcb.qingshoudan.entity.GatheringHistoryVoDetails;
import com.zcb.qingshoudan.entity.VerificationHistoryVoDetails;
import com.zcb.qingshoudan.xrecyclerview.ProgressStyle;
import com.zcb.qingshoudan.xrecyclerview.XRecyclerView;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class VerificationHistoryActivity extends Activity implements View.OnClickListener{
    private LinearLayout titleLinearLayout;
    private TextView titleTV;
    private XRecyclerView xRecyclerView;
    private LinearLayout h;
    private TextView i;
    private TextView j;
    private VerificationHistoryAdapter  verificationHistoryAdapter;
    private List<VerificationHistoryVoDetails> verificationHistoryVoDetailses;
//    private e m;
    private Button n;
    private LinearLayout o;
    private int p = 1;
    private boolean q = true;
    private Date r;
    private SimpleDateFormat s;
    private String t;
    private int u;
    private int v;
    private int w;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_verification_history);
        verificationHistoryVoDetailses=new ArrayList<VerificationHistoryVoDetails>();
        initData(5);
        initView();
    }
    private void initView(){
        xRecyclerView= (XRecyclerView) findViewById(R.id.verification_history_recyclerview);
        //title main
        titleLinearLayout= (LinearLayout) findViewById(R.id.title_lin_back);
        titleTV= (TextView) findViewById(R.id.title_text);
        titleLinearLayout.setVisibility(View.VISIBLE);
        titleLinearLayout.setOnClickListener(this);
        titleTV.setText("核销记录");

        //创建默认的线性LayoutManager
        LinearLayoutManager linearLayoutManager=new LinearLayoutManager(this);
        xRecyclerView.setLayoutManager(linearLayoutManager);
        //
        verificationHistoryAdapter=new VerificationHistoryAdapter(verificationHistoryVoDetailses);
        xRecyclerView.setAdapter(verificationHistoryAdapter);

        xRecyclerView.setRefreshProgressStyle(ProgressStyle.BallSpinFadeLoader);
        xRecyclerView.setLoadingMoreProgressStyle(ProgressStyle.BallRotate);
        xRecyclerView.setArrowImageView(R.drawable.iconfont_downgrey);
        View header= LayoutInflater.from(this).inflate(R.layout.activity_verification_history_layout,(ViewGroup)findViewById(android.R.id.content),false);
        xRecyclerView.addHeaderView(header);
        xRecyclerView.setLoadingListener(new XRecyclerView.LoadingListener() {
            @Override
            public void onRefresh() {
                new Handler().postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        initData(2);
                        verificationHistoryAdapter.notifyDataSetChanged();
                        xRecyclerView.refreshComplete();
                    }
                },2000);

            }

            @Override
            public void onLoadMore() {
                new Handler().postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        initData(3);
                        verificationHistoryAdapter.notifyDataSetChanged();
                        xRecyclerView.refresh();
                    }
                },5000);

            }
        });
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.title_lin_back:
                finish();
                break;
        }
    }

    private void initData(int length){
        for (int i=0;i<length;i++){
            VerificationHistoryVoDetails detail=new VerificationHistoryVoDetails();
            detail.setCardid("01002");
            detail.setMername("张三"+i);
            detail.setConsumetime("2016-11-30 12:12:30");

            verificationHistoryVoDetailses.add(detail);
        }
    }
}
